package com.jt.controller;

import com.jt.pojo.User;
import com.jt.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@CrossOrigin
public class UserController {
    @Autowired
    private UserService userService;
    //全表
    @GetMapping("findAll")
    public List<User> findAll(){
        return userService.findAll();
    }
    //删
    @DeleteMapping("/user/{id}")
    public String deleteUserById(@PathVariable Integer id){
        userService.deleteUserById(id);
        return "删除ID:"+id+"成功";
    }
    //增
    @PostMapping("/saveUser")
    public String addUserBtn(@RequestBody User user){
        userService.addUserBtn(user);
        System.out.println(user);
        return "新增成功";
    }
    //增restFul风格
    @PostMapping("/saveUser/{name}/{age}/{sex}")
    public String addUserBtn2(User user){
        userService.addUserBtn(user);
        System.out.println(user);
        return "添加成功";
    }
    //改
    @PutMapping("/updateUser")
    public String updateBtn(@RequestBody User user){
        userService.updateBtn(user);
        return "修改成功";
    }
}
